<?php
class KeywordAction extends AdminAction {
    //资源目录管理列表
	public function index(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$list = M('Keyword')->order('category asc')->select();
		foreach ($list as $k=>$v)
		{
			switch ($v['category'])
			{
				case 0:$list[$k]['category']="全站";break;
				case 1:$list[$k]['category']="图片";break;
				case 2:$list[$k]['category']="视频";break;
				case 3:$list[$k]['category']="动画";break;
				case 4:$list[$k]['category']="游戏";break;
				case 5:$list[$k]['category']="文章";break;
				case 6:$list[$k]['category']="挂图";break;
				case 7:$list[$k]['category']="图书";break;
				case 8:$list[$k]['category']="展品";break;
				case 9:$list[$k]['category']="知识题";break;
			}
		}
		$this->assign("list",$list);
		$this->display();
	}
	
  public function editcate(){
  		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$keyid=$_GET['keyid'];
  		if($_POST){
  			$data=$_POST;
  			$data['keyid']=$keyid;
  			$model=D('Keyword');
			if($model->create($data)){
				$model->save();
				$this->redirect('Keyword/index');
			}else{
				$rs['error'] = $model->getError();
				$this->assign('erorsta','1');
				$this->assign('error',$rs['error']);
			}
		}else{
			$info=M('Keyword')->find($keyid);
			$this->assign('info',$info);
			 }
       $this->display();
 }
	public function keyword(){
	   	$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
				$model=D('Keyword');
		if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
		{
			$cond = $_POST;
			if($model->create($cond)){   
			$model->add();
			$this->redirect('Keyword/index');
			}else{   
				$rs['error'] = $model->getError();
				$this->assign('erorsta','1');
				$this->assign('error',$rs['error']);
			}
		}
	   $this->display();
	}

//下降
	public function desc()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$keyid = $_POST['keyid'];
		
		if($keyid)
		{
			$map['keyid'] = $keyid;
			//$map["type"] = 1;
			$data["type"] = 0;
			$res = M('Keyword')->where($map)->save($data);
			if($res) echo 1;
			else echo 0;
		}

		else echo 0;
	}
	
	//上升
	public function asc()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$keyid = $_POST['keyid'];
		
		if($keyid)
		{
			$map['keyid'] = $keyid;
			//$map["type"] = 0;
			$data["type"] = 1;
			$res = M('Keyword')->where($map)->save($data);
			if($res) echo 1;
			else echo 0;
		}

		else echo 0;
	}
	
	//删除目录
	public function dele()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$keyid = $_POST['keyid'];
		
		if($keyid)
		{
			$map['keyid'] = $keyid;

			$res = M('Keyword')->where($map)->delete();
				if($res) echo 1;
				else echo 0;
       }
		
		else echo 0;
	}
 }
?>